<%@ page import="com.webtest.mvctest2.model.Customer" %>
<%@ page import="java.util.List" %><%--
  Created by IntelliJ IDEA.
  User: lzy
  Date: 2018/7/28
  Time: 10:01
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Customer Info</title>
    <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js">
    </script>

    <script type="text/javascript">
        $(function () {
            $(".delete").click(function () {
                var content = $(this).parent().parent().find("td:eq(1)").text();
                var flag = confirm("确定要删除" + content + "的信息么?");
                return flag;
            });
        });
    </script>
</head>
<body>
<br>
<form action="query.do" method="post">
    <table>
        <tr>
            <td>Customer Name</td>
            <td><input type="text" name="name"/></td>
        </tr>
        <tr>
            <td>Address</td>
            <td><input type="text" name="address"/></td>
        </tr>
        <tr>
            <td>Phone:</td>
            <td><input type="text" name="phone"/></td>
        </tr>
        <tr>
            <td><input type="submit" value="Query"/></td>
            <td><a href="newcustomer.jsp">Create New Customer</a></td>
        </tr>
    </table>
</form>
<br>
<hr>
<br>
<%
    List<Customer> customers = (List<Customer>) request.getAttribute("customers");
    if (customers != null && customers.size() > 0) {
%>
<table border="1" cellpadding="10" cellspacing="1">
    <tr>
        <th>ID</th>
        <th>CustomerName</th>
        <th>Address</th>
        <th>Phone</th>
        <th>UPDATE\DELETE</th>
    </tr>
    <%
        for (Customer customer : customers) {
    %>

    <tr>
        <td><%=customer.getId()%>
        </td>
        <td><%=customer.getName()%>
        </td>
        <td><%=customer.getAddress()%>
        </td>
        <td><%=customer.getPhone()%>
        </td>
        <td>
            <a href="editCustomer.do?id=<%=customer.getId()%>">UPDATE</a>
            <a href="deleteCustomer.do?id=<%=customer.getId()%>" class="delete">DELETE</a>
        </td>
    </tr>


    <%
        }
    %>

</table>
<%
    }
%>
</body>
</html>
